/*
 * @Author: 
 * @Date: 2025-07-30 17:49:14
 * @LastEditor: zhuxiaoyi
 * @LastEditTime: 2025-07-30 17:49:37
 * @Description: 
 */
// feedback.controller.ts
import { Controller, Inject, Post, Get, Put, Del, Param, Body, Query } from '@midwayjs/core';
import { ApiTags, ApiOperation, ApiResponse } from '@midwayjs/swagger';
import { FeedbackService } from '../service/feedBack.service';
import { Feedback } from '../entity/feedBack.entity';
import { CreateFeedbackDto, UpdateFeedbackDto, FeedbackRatingDto, QueryFeedbackDto } from '../dto/feedBack.dto';

@ApiTags('feedback')
@Controller('/api/feedback')
export class FeedbackController {
  @Inject()
  feedbackService: FeedbackService;

  @ApiOperation({ summary: '创建反馈' })
  @ApiResponse({ status: 201, type: Feedback })
  @Post('/')
  async create(@Body() dto: CreateFeedbackDto): Promise<Feedback> {
    return await this.feedbackService.create(dto);
  }

  @ApiOperation({ summary: '更新反馈' })
  @ApiResponse({ status: 200, type: Feedback })
  @Put('/:id')
  async update(@Param('id') id: number, @Body() dto: UpdateFeedbackDto): Promise<Feedback> {
    return await this.feedbackService.update(id, dto);
  }

  @ApiOperation({ summary: '提交评分' })
  @ApiResponse({ status: 200, type: Feedback })
  @Post('/:id/rating')
  async submitRating(@Param('id') id: number, @Body() dto: FeedbackRatingDto): Promise<Feedback> {
    return await this.feedbackService.submitRating(id, dto);
  }

  @ApiOperation({ summary: '获取反馈详情' })
  @ApiResponse({ status: 200, type: Feedback })
  @Get('/:id')
  async getById(@Param('id') id: number): Promise<Feedback> {
    return await this.feedbackService.findById(id);
  }

  @ApiOperation({ summary: '查询反馈列表' })
  @ApiResponse({ status: 200, description: '反馈列表及总数' })
  @Get('/')
  async findAll(@Query() query: QueryFeedbackDto): Promise<{ list: Feedback[], total: number }> {
    return await this.feedbackService.findAll(query);
  }

  @ApiOperation({ summary: '删除反馈' })
  @ApiResponse({ status: 200, type: Boolean })
  @Del('/:id')
  async remove(@Param('id') id: number): Promise<boolean> {
    return await this.feedbackService.remove(id);
  }

  @ApiOperation({ summary: '标记为已读' })
  @ApiResponse({ status: 200, type: Boolean })
  @Put('/:id/read')
  async markAsRead(@Param('id') id: number): Promise<boolean> {
    return await this.feedbackService.markAsRead(id);
  }
}
